/* $RCSFile: ADNDynSalesBase.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/CRMWrapper3/DynEntities/ADNDynSalesBase.cs $
 * $log$
 * Revision 19 2010/10/02 14:01:49  christian.surieux
 *   Corrected a bug in allmost everyADNDyn file for PrimaryFieldVualue
 * Revision 6 2010/08/06 19:56:33  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using System.Globalization;

using CrmSdk;

namespace AddonNice.CRMWrapper
{
	/// <summary>
	/// Base class for quote / salesorder / invoice
	/// </summary>
    public class ADNDynSalesBase : DynEntity
	{
        public override bool HasOwningBusinessUnitProperty
        {
            get{   return true;}
        }

        /// <summary>
		/// Reserved for template methods: do not use directly
		/// </summary>
        public ADNDynSalesBase(): base()
		{}

        public ADNDynSalesBase(CRMWrapperBase w, string entity)
			: base(w, entity)
		{}

		public ADNDynSalesBase(CRMWrapperBase w,string entity,Guid CrmId)
			: base(w,entity, CrmId)
		{}

		public ADNDynSalesBase(CRMWrapperBase w,string entName,InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(w,entName,e,prop,s)
		{}

        public ADNDynSalesBase(ResetWrapperHandler fn, string entity)
			: base(fn,entity)
		{}

		public ADNDynSalesBase(ResetWrapperHandler fn,string entity,Guid CrmId)
			: base(fn,entity, CrmId)
		{}

		public ADNDynSalesBase(ResetWrapperHandler fn,string entName,InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(fn,entName,e,prop,s)
		{}

        public override string PrimaryFieldName
        {
            get
            {
               return CrmStr.name;
            }
           set
           {}
        }

        /// <summary>
        /// Value contained in the PrimaryField for the DynEntity or empty if no PrimaryField
        /// </summary>
        public override string PrimaryFieldStringValue
        {
            get
            {
                return name;
            }
            set
            {
                name =   value;
            }
        }

        /// <summary>
        /// Gets the exchange rate for the currency associated with the product with respect to the base currency.
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal exchangerate
        {
            get
            {
                return DecimalPropertyValue(CrmStr.exchangerate);
            }
            set
            {
                AddDecimalProperty(CrmStr.exchangerate,value);
            }
        }

        /// <summary>
        /// Gets and sets the ID of the currency associated with the product.         
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public Guid transactioncurrencyid
        {
            get
            {
                return LookupPropertyValue(CrmStr.transactioncurrencyid);
            }
            set
            {
                AddLookupProperty(CrmStr.transactioncurrencyid,CrmStr.transactioncurrency,value);
            }
        }

        public string transactioncurrencyName
        {
            get
            {
                return LookupPropertyName(CrmStr.transactioncurrencyid);
            }
        }

        /// <summary>
        /// Contains the description of the quote/order/invoice. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string description 
        {
            get
            {
                return StringPropertyValue(CrmStr.description);
            }
            set
            {
                AddStringProperty(CrmStr.description,value);
            }
        }
        
        /// <summary>
        /// Gets or sets the value that indicates if the sales order products are shipped or picked up by the customer.
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public bool willcall
        {
            get 
            {
                return BooleanPropertyValue(CrmStr.willcall);
            }
            set
            {
            
                AddBooleanProperty(CrmStr.willcall,value);
            }
        }
         
        /// <summary>
        /// Gets or sets the freight terms for the order. 
        /// FOB
        /// No Charge
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public int freighttermscode 
        {
            get
            {
                return PicklistPropertyIntValue(CrmStr.freighttermscode);
            }
            set
            {
                AddPicklistProperty(CrmStr.freighttermscode,value);
            }
        }
 
        public string freighttermscodeLabel
        {
            get
            {
                return PicklistPropertyLabelValue(CrmStr.freighttermscode);
            }
        }

        /// <summary>
        /// Gets or sets the payment terms for the order. 
        /// 2% 10, Net 30
        /// Net 30
        /// Net 45
        /// Net 60
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public int paymenttermscode
        {
            get
            {
                return PicklistPropertyIntValue(CrmStr.paymenttermscode);
            }
            set
            {
                AddPicklistProperty(CrmStr.paymenttermscode,value);
            }
        }
        
        public string paymenttermscodeLabel
        {
            get
            {
                return PicklistPropertyLabelValue(CrmStr.paymenttermscode);
            }
        }

        /// <summary>
        /// Gets or sets the pricing error for the order. 
        /// None 
        /// Detail Error
        /// Missing Price Level
        /// Inactive Price Level
        /// Missing Quantity
        /// Missing Unit Price
        /// Missing Product
        /// Invalid Product
        /// Missing Pricing Code
        /// Invalid Pricing Code
        /// Missing UOM
        /// Product Not In Price Level
        /// Missing Price Level Amount
        /// Missing Price Level Percentage
        /// Missing Price
        /// Missing Current Cost
        /// Missing Standard Cost
        /// Invalid Price Level Amount
        /// Invalid Price Level Percentage
        /// Invalid Price
        /// Invalid Current Cost
        /// Invalid Standard Cost
        /// Invalid Rounding Policy
        /// Invalid Rounding Option
        /// Invalid Rounding Amount
        /// Price Calculation Error
        /// Invalid Discount Type
        /// Discount Type Invalid State
        /// Invalid Discount
        /// Invalid Quantity
        /// Invalid Pricing Precision
        /// Missing Product Default UOM
        /// Missing Product UOM Schedule
        /// Inactive Discount Type
        /// Invalid Price Level Currency
        /// Price Attribute Out Of Range
        /// Base Currency Attribute Overflow
        /// Base Currency Attribute Underflow
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public int pricingerrorcode
        {
            get
            {
                return PicklistPropertyIntValue(CrmStr.pricingerrorcode);
            }
            set
            {
                AddPicklistProperty(CrmStr.pricingerrorcode,value);
            }
        }
         
        public string pricingerrorcodeLabel
        {
            get
            {
                return PicklistPropertyLabelValue(CrmStr.pricingerrorcode);
            }
        }

        /// <summary>
        /// Gets or sets the method of shipment for the order. 
        /// Airborne
        /// DHL
        /// FedEx
        /// Full Load
        /// Postal Mail
        /// UPS
        /// Will Call
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public int shippingmethodcode
        {
            get
            {
                return PicklistPropertyIntValue(CrmStr.shippingmethodcode);
            }
            set
            {
                AddPicklistProperty(CrmStr.shippingmethodcode,value);
            }
        }

        public string shippingmethodcodeLabel
        {
            get
            {
                return PicklistPropertyLabelValue(CrmStr.shippingmethodcode);
            }
        }

        /// <summary>
        /// Gets or sets the discount, as a monetary amount, for the order. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal discountamount
        {
            get
            {
                return MoneyPropertyValue(CrmStr.discountamount);
            }
            set
            {
                AddMoneyProperty(CrmStr.discountamount,value);
            }
        }

        /// <summary>
        /// Gets the base currency equivalent of the discount specified as a monetary amount for the order.
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal discountamount_base
        {
            get
            {
                return MoneyPropertyValue(CrmStr.discountamount_base);
            }
        }
        
        /// <summary>
        /// Gets or sets the discount, as a percentage, for the order. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal discountpercentage
        {
            get
            {
                return DecimalPropertyValue(CrmStr.discountpercentage);
            }
            set
            {
                AddDecimalProperty(CrmStr.discountpercentage,value);
            }
        }

        /// <summary>
        /// Gets or sets the cost of freight for the order. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal freightamount
        {
            get
            {
                return MoneyPropertyValue(CrmStr.freightamount);
            }
            set
            {
                AddMoneyProperty(CrmStr.freightamount,value);
            }
        }

        /// <summary>
        /// Gets the base currency equivalent for the cost of freight on the order. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal freightamount_base
        {
            get
            {
                return MoneyPropertyValue(CrmStr.freightamount_base);
            }
        }

        /// <summary>
        /// Gets the total amount for the order. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal totalamount
        {
            get 
            {
                return MoneyPropertyValue(CrmStr.totalamount);
            }
            set
            {
                AddMoneyProperty(CrmStr.totalamount,value);
            }
        }

        /// <summary>
        /// Gets the base currency equivalent of the total amount for the order. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal totalamount_base
        {
            get 
            {
                return MoneyPropertyValue(CrmStr.totalamount_base);
            }
        }
        
        /// <summary>
        /// Gets the total amount minus the freight charges for the order.
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal totalamountlessfreight
        {
            get 
            {
                return MoneyPropertyValue(CrmStr.totalamountlessfreight);
            }
            set
            {
                AddMoneyProperty(CrmStr.totalamountlessfreight,value);
            }
        }

        /// <summary>
        /// Gets the base currency equivalent of the total amount minus the freight charges for the order.. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal totalamountlessfreight_base
        {
            get 
            {
                return MoneyPropertyValue(CrmStr.totalamountlessfreight_base);
            }
        }


        /// <summary>
        /// Gets the total discount for the order. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal totaldiscountamount
        {
            get 
            {
                return MoneyPropertyValue(CrmStr.totaldiscountamount);
            }
            set
            {
                AddMoneyProperty(CrmStr.totaldiscountamount,value);
            }
        }

        /// <summary>
        /// Gets the base currency equivalent of the total discount for the order. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal totaldiscountamount_base
        {
            get 
            {
                return MoneyPropertyValue(CrmStr.totaldiscountamount_base);
            }
        }

        /// <summary>
        /// Gets the total line item amount for the order. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal totallineitemamount
        {
            get 
            {
                return MoneyPropertyValue(CrmStr.totallineitemamount);
            }
            set
            {
                AddMoneyProperty(CrmStr.totallineitemamount,value);
            }
        }

        /// <summary>
        /// Gets the base currency equivalent of the total line item amount for the order. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal totallineitemamount_base
        {
            get 
            {
                return MoneyPropertyValue(CrmStr.totallineitemamount_base);
            }
        }

        /// <summary>
        /// Gets the total line item amount for the order. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal totallineitemdiscountamount
        {
            get 
            {
                return MoneyPropertyValue(CrmStr.totallineitemdiscountamount);
            }
            set
            {
                AddMoneyProperty(CrmStr.totallineitemdiscountamount,value);
            }
        }

        /// <summary>
        /// Gets the base  currency equivalent of the total line item discount for the order. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal totallineitemdiscountamount_base
        {
            get 
            {
                return MoneyPropertyValue(CrmStr.totallineitemdiscountamount_base);
            }
        }

         
        /// <summary>
        /// Gets the total tax for the order.
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal totaltax
        {
            get 
            {
                return MoneyPropertyValue(CrmStr.totaltax);
            }
            set
            {
                AddMoneyProperty(CrmStr.totaltax,value);
            }
        }

        /// <summary>
        /// Gets the base currency equivalent of the total tax on the order. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public decimal totaltax_base
        {
            get 
            {
                return MoneyPropertyValue(CrmStr.totaltax_base);
            }
        }

        /// <summary>
        /// Gets or sets the ID of the opportunity associated
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public Guid opportunityid
        {
            get 
            {
                return LookupPropertyValue(CrmStr.opportunityid);
            }
            set
            {
                AddLookupProperty(CrmStr.opportunityid,CrmStr.opportunity,value);
            }
        }
 
        /// <summary>
        /// Specifies the ID of the price list associated with the product. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public Guid pricelevelid
        {
            get 
            {
                return LookupPropertyValue(CrmStr.pricelevelid);
            }
            set
            {
                AddLookupProperty(CrmStr.pricelevelid,CrmStr.pricelevel,value);
            }
        }
 
        public string pricelevelName
        {
            get 
            {
                if ( ContainsKey(CrmStr.pricelevelid) )
                    return LookupPropertyName(CrmStr.pricelevelid);
                return string.Empty;
            }
        }

        #region customer

        string _DefaultCustomerName   =   CrmStr.account;
		public string DefaultCustomerName
		{
			get
			{
				return _DefaultCustomerName;
			}
			set
			{
                switch (value)
                {
                    case CrmStr.account:
                    case CrmStr.contact:
                        _DefaultCustomerName  =   value;
                        break;
                }
			}
		}

        /// <summary>
        /// Beware : set defaults to account, to change it set DefaultCustomerName property before calling set
        /// or use SetContactCustomerid for adding contacts
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public Guid customerid 
        {
            get 
            {
                return CustomerPropertyValue(CrmStr.customerid);
            }
            set 
            {
                AddCustomerProperty(CrmStr.customerid,DefaultCustomerName,value);
            }
        }

        /// <summary>
        /// The entity : account or contact
        /// </summary>
        public string customerType
        {
            get 
            {
                return CustomerPropertyType(CrmStr.customerid);
            }
        }

         /// <summary>
        /// To adding contact customerids
        /// </summary>
        public void SetContactCustomerid(Guid contactid)
        {
                AddCustomerProperty(CrmStr.customerid,CrmStr.contact,contactid);
        }

        #endregion customer
        
        /// <summary>
        /// Gets or sets the ID of the source campaign associated with the order. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public Guid campaignid
        {
            get 
            {
                if ( ContainsKey(CrmStr.campaignid) )
                    return LookupPropertyValue(CrmStr.campaignid);
                return Guid.Empty;
            }
            set
            {
                AddLookupProperty(CrmStr.campaignid,CrmStr.campaign,value);
            }
        }

        public string campaignName
        {
            get
            {
                if (ContainsKey(CrmStr.campaignid))
                    return LookupPropertyName(CrmStr.campaignid);
                return string.Empty;
            }
        }
       
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string billto_line1
        {
            get
            {
                return StringPropertyValue(CrmStr.billtoline1);
            }
            set
            {
                AddStringProperty(CrmStr.billtoline1,value);
            }
        }

        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string billto_line2
        {
            get
            {
                return StringPropertyValue(CrmStr.billtoline2);
            }
            set
            {
                AddStringProperty(CrmStr.billtoline2,value);
            }
        }

        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string billto_line3
        {
            get
            {
                return StringPropertyValue(CrmStr.billtoline3);
            }
            set
            {
                AddStringProperty(CrmStr.billtoline3,value);
            }
        }

        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string billto_city
        {
            get
            {
                return StringPropertyValue(CrmStr.billtocity);
            }
            set
            {
                AddStringProperty(CrmStr.billtocity,value);
            }
        }

        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string billto_county
        {
            get
            {
                return StringPropertyValue(CrmStr.billtocounty);
            }
            set
            {
                AddStringProperty(CrmStr.billtocounty,value);
            }
        }

        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string billto_country
        {
            get
            {
                return StringPropertyValue(CrmStr.billtocountry);
            }
            set
            {
                AddStringProperty(CrmStr.billtocountry,value);
            }
        }

        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string billto_postalcode
        {
            get
            {
                return StringPropertyValue(CrmStr.billtopostalcode);
            }
            set
            {
                AddStringProperty(CrmStr.billtopostalcode,value);
            }
        }
     
        /// <summary>
        /// Gets or sets the fax number for the billing address. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string billto_fax
        {
            get
            {
                return StringPropertyValue(CrmStr.billtofax);
            }
            set
            {
                AddStringProperty(CrmStr.billtofax,value);
            }
        }

        /// <summary>
        /// Gets or sets the telephone number associated with the billing address. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string billto_telephone
        {
            get
            {
                return StringPropertyValue(CrmStr.billtophone);
            }
            set
            {
                AddStringProperty(CrmStr.billtophone,value);
            }
        }

        
        /// <summary>
        /// billto_name Gets or sets the name to enter for the billing address. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string billto_name
        {
            get
            {
                return StringPropertyValue(CrmStr.billto_name);
            }
            set
            {
                AddStringProperty(CrmStr.billto_name,value);
            }
        }

        /// <summary>
        /// Gets or sets the state or province in the billing address. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string billto_stateorprovince
        {
            get
            {
                return StringPropertyValue(CrmStr.billtostate);
            }
            set
            {
                AddStringProperty(CrmStr.billtostate,value);
            }
        }

        /// <summary>
        /// Gets or sets the contact name for the billing address. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string billto_contactname
        {
            get
            {
                return StringPropertyValue(CrmStr.billtocontactname);
            }
            set
            {
                AddStringProperty(CrmStr.billtocontactname,value);
            }
        }

        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string shipto_line1
        {
            get
            {
                return StringPropertyValue(CrmStr.shiptoline1);
            }
            set
            {
                AddStringProperty(CrmStr.shiptoline1,value);
            }
        }

        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string shipto_line2
        {
            get
            {
                return StringPropertyValue(CrmStr.shiptoline2);
            }
            set
            {
                AddStringProperty(CrmStr.shiptoline2,value);
            }
        }

        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string shipto_line3
        {
            get
            {
                return StringPropertyValue(CrmStr.shiptoline3);
            }
            set
            {
                AddStringProperty(CrmStr.shiptoline3,value);
            }
        }

        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string shipto_city
        {
            get
            {
                return StringPropertyValue(CrmStr.shiptocity);
            }
            set
            {
                AddStringProperty(CrmStr.shiptocity,value);
            }
        }

        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string shipto_county
        {
            get
            {
                return StringPropertyValue(CrmStr.shiptocounty);
            }
            set
            {
                AddStringProperty(CrmStr.shiptocounty,value);
            }
        }

        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string shipto_country
        {
            get
            {
                return StringPropertyValue(CrmStr.shiptocountry);
            }
            set
            {
                AddStringProperty(CrmStr.shiptocountry,value);
            }
        }

        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string shipto_postalcode
        {
            get
            {
                return StringPropertyValue(CrmStr.shiptopostalcode);
            }
            set
            {
                AddStringProperty(CrmStr.shiptopostalcode,value);
            }
        }

        /// <summary>
        /// Gets or sets the fax number for the shipping address. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string shipto_fax
        {
            get
            {
                return StringPropertyValue(CrmStr.shiptofax);
            }
            set
            {
                AddStringProperty(CrmStr.shiptofax,value);
            }
        }

        /// <summary>
        /// Gets or sets the telephone number associated with the billing address. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string shipto_telephone
        {
            get
            {
                return StringPropertyValue(CrmStr.shiptophone);
            }
            set
            {
                AddStringProperty(CrmStr.shiptophone,value);
            }
        }

        
        /// <summary>
        /// Gets or sets the name to enter in the shipping address. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string shipto_name
        {
            get
            {
                return StringPropertyValue(CrmStr.shipto_name);
            }
            set
            {
                AddStringProperty(CrmStr.shipto_name,value);
            }
        }

        /// <summary>
        /// Gets or sets the state or province in the shipping address. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string shipto_stateorprovince
        {
            get
            {
                return StringPropertyValue(CrmStr.shiptostate);
            }
            set
            {
                AddStringProperty(CrmStr.shiptostate,value);
            }
        }

        /// <summary>
        /// Gets or sets the contact name for the shipping address. 
        /// </summary>
        [CrmDynAttribute(CrmStr.salesorder), CrmDynAttribute(CrmStr.quote),CrmDynAttribute(CrmStr.invoice)]
        public string shipto_contactname
        {
            get
            {
                return StringPropertyValue(CrmStr.shiptocontactname);
            }
            set
            {
                AddStringProperty(CrmStr.shiptocontactname,value);
            }
        }
        
        public string owningbusinessunitName
        {
            get
            {
                return LookupPropertyName(CrmStr.owningbusinessunit);
            }
        }

        public ADNDynCustomer RetrieveCustomer()
        {
            if (CRMDynTraceSwitch.Sw.TraceVerbose)
                Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]ADNDynSalesBase RetrieveCustomer BEG Entity: {0}, customerid: {1}",
                    customerType,customerid),CRMDynTraceSwitch.Sw.Info);
            
            switch(customerType)
            {
                case CrmStr.account:
                    ADNDynAccount waccount  =   new ADNDynAccount(wrapper,customerid);
                    waccount.adminRetrieve();
                    if ( waccount != null )
                    {
                        if ( CRMDynTraceSwitch.Sw.TraceVerbose )
                            Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]ADNDynSalesBase RetrieveCustomer found account: {0}-{1}",
                                waccount.name,waccount.accountid),CRMDynTraceSwitch.Sw.Info);
                        return waccount;
                    }
                    break;
                case CrmStr.contact:
                    ADNDynContact wcontact   =   new ADNDynContact(wrapper,customerid);
                    wcontact.adminRetrieve();
                    if ( wcontact != null )
                    {
                        if ( CRMDynTraceSwitch.Sw.TraceVerbose )
                            Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]ADNDynSalesBase RetrieveCustomer found contact: {0}-{1}",
                                wcontact.lastname,wcontact.contactid),CRMDynTraceSwitch.Sw.Info);
                        return wcontact;
                    }
                    break;

                case CrmStr.lead:
                    ADNDynLead wlead         =   new ADNDynLead(wrapper,customerid);
                    wlead.adminRetrieve();
                    if ( wlead != null )
                    {
                        if ( CRMDynTraceSwitch.Sw.TraceVerbose )
                            Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]ADNDynSalesBase RetrieveCustomer found lead: {0}-{1}",
                                wlead.lastname,wlead.leadid),CRMDynTraceSwitch.Sw.Info);
                        return wlead;
                    }
                    break;
            }
            return null;
        }
    }
}